package com.example.vue_shop.components.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.vue_shop.components.order.entity.ShopOrder;
import com.example.vue_shop.components.order.mapper.ShopOrderMapper;
import com.example.vue_shop.components.order.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lipengwei
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Resource(name = "shopOrderMapper")
    private ShopOrderMapper orderMapper;

    @Override
    public Map<String, Object> getOrderList(String query, int pageNum, int pageSize) {
        Page<ShopOrder> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);

        QueryWrapper<ShopOrder> queryWrapper = new QueryWrapper<>();

        Page<ShopOrder> orderPage = orderMapper.selectPage(page, queryWrapper);

        Map<String, Object> result = new HashMap<>(2);
        result.put("orderList", orderPage.getRecords());
        result.put("total", orderPage.getTotal());
        return result;
    }
}
